<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

<div class="bjui-pageHeader" style="background-color:#fefefe; border-bottom:none;">
    <form data-toggle="ajaxsearch" data-options="{searchDatagrid:$.CurrentNavtab.find('#userCapital_table')}">
        <fieldset>
            <legend style="font-weight:normal;">条件搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;">
                <span>用户名：</span>
                <input type="text" name="userModel.userName" class="form-control" size="11">
                    
                <label class="row-label">&nbsp;时间查询：</label>
                <input type="text" name="from" data-toggle="datepicker" data-nobtn="true" size="11">
                -
                <input type="text" name="to" data-toggle="datepicker" data-nobtn="true" size="11">
                    
                <div class="btn-group">
                    <button type="submit" class="btn-green" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<div class="bjui-pageContent">
    <table id="userCapital_table" class="table table-bordered"></table>
    <script type="text/javascript">
        var userCp_table;
        $(function () {
            userCp_table = $('#userCapital_table').datagrid({
                height: '100%',
                width: '100%',
                fullGrid : true,
                showToolbar: false,
                filterThead: false,
                showTfoot : true,
                delPK: 'id',
                dataUrl: '/admin/user/allUser?c=a&a=' + new Date().getTime(),
                local: "remote",
                inlineEditMult: false,
                saveAll: false,
                postData : {
                    totalProfit : "userCp_profit",
                    totalBalance : "userCp_balance",
                    totalFreezing : "userCp_freezing"
                },
                columns: [
                    {
                        render: userCapitalOpenDialogShowUser,
                        label: '用户名',
                        align: 'center'
                    }, {
                        name: 'accountModel',
                        label: '可用余额',
                        align: 'center',
                        render: function (value) {
                            if (value) {
                                return value.balance;
                            }
                        },
                        total: 'userCp_balance'
                    }, {
                        name: 'accountModel',
                        label: '冻结金额',
                        align: 'center',
                        render: function (value) {
                            if (value) {
                                return value.freezing;
                            }
                        },
                        total: 'userCp_freezing'
                    }, {
                        name: 'accountModel',
                        label: '资产总额',
                        align: 'center',
                        render: function (value) {
                            if (value) {
                                return value.balance + value.freezing;
                            }
                        },
                        total: 'totalProperty'
                    }, {
                        name: 'lastLoginDate',
                        label: '最后登录',
                        align: 'center',
                        pattern: 'yyyy-MM-dd HH:mm:ss',
                        render: function (value) {
                            return value ? value.substr(0, 19) : value
                        }
                    }
                ],
                linenumberAll: true,
                paging: {pageSize: 20, pageIndex: 1}
            });

        });


        function userCapitalExport() {
            var dates = $(userCp_table).data('selectedDatas');
            if (dates && dates.length !== 0) {
                var ids = [];
                dates.forEach(function (e) {
                    ids.push(e.id);
                });
                BJUI.ajax('ajaxdownload', {
                    url: '/admin/user/export',
                    data: {ids: ids.join(",")}
                });
            } else
                BJUI.alertmsg('info', BJUI.getRegional('datagrid.selectMsg'))
        }


        function userCapitalOpenDialogShowUser(value, data) {
            return '<a href="javascript:;" onclick="userCapitalOpenDialog(\'' + data.id + "','" + data.userName + '\')">' + data.userName + '</a>';
        }

        function userCapitalOpenDialog(id, userName) {
            BJUI.dialog({
                id: 'userInfo_' + id,
                url: '/admin/user/userInfo?id=' + id,
                title: '' + userName + '用户信息',
                width: 1200,
                height: 1200 * 0.618
            });
        }
    </script>
</div>
